// src/api/logging.js
import apiClient from './index';

/**
 * 获取指定存储桶的日志配置
 * @param {string} bucketName - 桶名称
 * @returns {Promise<Object>}
 */
export const getBucketLoggingConfig = (bucketName) => {
    return apiClient.get(`/api/v1/buckets/${bucketName}/logging`);
};

/**
 * 设置（开启/更新）存储桶的日志配置
 * @param {string} bucketName - 桶名称
 * @param {Object} config - { target_bucket, target_prefix }
 * @returns {Promise<Object>}
 */
export const setBucketLoggingConfig = (bucketName, config) => {
    return apiClient.put(`/api/v1/buckets/${bucketName}/logging`, config);
};

/**
 * 关闭存储桶的日志配置
 * @param {string} bucketName - 桶名称
 * @returns {Promise<Object>}
 */
export const deleteBucketLoggingConfig = (bucketName) => {
    return apiClient.delete(`/api/v1/buckets/${bucketName}/logging`);
};

/**
 * 获取所有存储桶列表（用于下拉选择）
 * @returns {Promise<Object>}
 */
export const getAllBuckets = () => {
    return apiClient.get('/api/v1/buckets');
};

// src/api/logging.js (在文件末尾添加)

/**
 * 分页列出日志文件
 * @param {string} targetBucket - 存放日志的桶
 * @param {string} prefix - 日志文件前缀
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise<Object>}
 */
export const listLogFiles = (targetBucket, prefix, page, limit) => {
    return apiClient.get(`/api/v1/buckets/${targetBucket}/logs`, {
        params: { prefix, page, limit }
    });
};

/**
 * 分页读取和解析日志文件内容
 * @param {string} targetBucket - 存放日志的桶
 * @param {string} key - 日志文件的完整key
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise<Object>}
 */
export const readLogContent = (targetBucket, key, page, limit) => {
    return apiClient.get(`/api/v1/buckets/${targetBucket}/logs/content`, {
        params: { key, page, limit }
    });
};